package hengtiansoft.com.myapplication.volley;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

import hengtiansoft.com.myapplication.BaseActivity;
import hengtiansoft.com.myapplication.R;

/**
 * Created by lu on 16/3/22.
 */
public class SecondVolley extends BaseActivity {
    Volley volley;
    RequestQueue queue;
    TextView baiduMsg, Weather, test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.firstview);
        queue = Volley.newRequestQueue(this);
        super.onCreate(savedInstanceState);

    }

    @Override
    public void initView() {
        baiduMsg = (TextView) findViewById(R.id.baidu);
        Weather = (TextView) findViewById(R.id.weather);

        StringRequest stringRequest =
                new StringRequest(Request.Method.POST,"https://www.baidu.com", new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        Log.v("Response", "Success:baidu");
                        baiduMsg.setText(String.valueOf(s));
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                }) {
                    protected Map<String, String> getParams() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("user", "");
                        params.put("pass", "");
                        params.put("comment", "");
                        return params;
                    }
                };

        CharsetJsonRequest weather = new CharsetJsonRequest("http://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        Log.v("Response", "Success:weather");

                        Weather.setText(s);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.v("error", "ErrorMsg:" + volleyError.getMessage());
            }
        });
        queue.add(weather);

    }


    @Override
    public void initData() {

    }
}
